;

class ChangePass {
    constructor(ChangePassWordElementSelector) {
        this.ChangePassWordEle = $(ChangePassWordElementSelector);
    }

    addEventListener() {
        let that = this;
        console.log(this.ChangePassWordEle)
        this.ChangePassWordEle.on('click',function () {

            let old = $('#old1').val();
            let new1 = $('#new').val();
            let new2 = $('#new1').val();

            if(new1 !== new2){
                $('#tit').text('修改失败');
                $('#content').text('两次密码不一致');
                $('#alerts').click();
                return
            }
            if(!old){
                $('#tit').text('修改失败');
                $('#content').text('旧密码输入错误');
                $('#alerts').click();
                return
            }

            $.ajax({
                url:'/front/changepwd/',
                data:{
                    'old':old,
                    'new':new1,
                    'csrf_token':$('#csrf').attr('content')
                },
                type:'post',
                success:function (data) {
                    if(data.code === 200){
                        $('#tit').text('修改成功');
                        $('#content').text('密码修改成功');
                        $('#alerts').click();
                    }else{
                        $('#tit').text('修改失败');
                        $('#content').text(data.message);
                        $('#alerts').click();
                    }
                },
                error:function (error) {
                    $('#tit').text('修改失败');
                        $('#content').text('网络错误');
                        $('#alerts').click();
                }
            })
        })

    }
}

$(
    function () {
        let c = new ChangePass('#con');
        c.addEventListener()
    }
);